﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Log4NetTest
{
    public partial class frmMain : Form
    {
        //Here is the once-per-class call to initialize the log object
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        //private static readonly log4net.ILog log = log4net.LogManager.GetLogger("Log4NetTest.OtherClass");

        public frmMain()
        {
            InitializeComponent();

        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            log.Info("La aplicacion fue iniciado.");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            log.Info("Se presiono botom ramdom");
            Random r = new Random();
            
            label4.Text = r.Next(10).ToString();
            log.Debug("El numero random es : "+label4.Text);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                log.Info("Se presiono el boton dividir");
                label3.Text = (Convert.ToDouble(textBox1.Text) / Convert.ToDouble(textBox2.Text)).ToString();
                log.Info("Se calculo el resultado de la division");
                log.Debug("Variable 1: " + textBox1.Text);
                log.Debug("Variable 2: " + textBox2.Text);
                log.Debug("El resultado de la division fue: "+label3.Text);            
            }
            catch (InvalidCastException x)
            {
                log.Error("valores invalidos", x);
            }
            catch (Exception x)
            {
                string texto = "Excepcion ocurrida";
                texto += " variable 1: " + textBox1.Text;
                texto += " variable 2: " + textBox2.Text;
                log.Fatal(texto, x);
            }
        }
    }
}
